//
//  WellcomeViewController.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/20.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

import SnapKit

import SDWebImage

class WellcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.setupUI()
        
//        //更新约束
//        icon.snp_updateConstraints { (make) -> Void in
//            make.top.equalTo(200)
//        }
//        
//        
//        //执行动画
//        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
//            self.view.layoutIfNeeded()
//            }) { (_) -> Void in
//                UIView.animateKeyframesWithDuration(1, delay: 0, options: [], animations: { () -> Void in
//                    self.wellcomeLabel.alpha = 1
//                    }, completion: { (_) -> Void in
//                        //显示控制器
//                })
//        }
        
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(false)
        
        
        //更新约束
        icon.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(200)
        }
        
        
        //执行动画
        UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateKeyframesWithDuration(1, delay: 0, options: [], animations: { () -> Void in
                    self.wellcomeLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        //显示控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(HMChangeRootVCNotification, object: self)
                })
        }
    }
    
    private func setupUI(){
        self.view.backgroundColor = UIColor.whiteColor()
        
        view.addSubview(icon)
        view.addSubview(wellcomeLabel)
        
        
        icon.snp_makeConstraints(closure: { (make) -> Void in
//            make.center.equalTo(self.view)
//             make.size.equalTo(CGSize(width: 80, height: 80))
            
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view)
            make.top.equalTo(350)

        })
        wellcomeLabel.snp_makeConstraints(closure: { (make) -> Void in
            make.top.equalTo(icon.snp_bottom).offset(20)
            make.centerX.equalTo(icon)
        })
        
    }
    
    
    
    
    //MARK - 懒加载控件
    lazy var icon:UIImageView = {
       let imageView = UIImageView(image: UIImage(named:"avatar_default_big" ))
        if let image:String = UserAccountViewModel.shareUserAccountViewModel.account?.avatar_large{
            imageView.sd_setImageWithURL(NSURL(string: image))
        }
        
        
        imageView.layer.cornerRadius = 40
        imageView.layer.masksToBounds = true
        return imageView
    }()
    
    lazy var wellcomeLabel:UILabel = {
        let label = UILabel(textColor: UIColor.blackColor(), fontSize: 14, preferredMaxLayoutWidth: 100)
        label.text = "欢迎回来"
        label.alpha = 0
        return label
        
    }()
    
    
    

   
}
